<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>随机点名</title>
</head>
<body>
<div id="content">

    <span id="kaiShi">
        开始
    </span>

    <br>

    <button id="zanTing">
        开始
    </button>

</div>

<script>
    var arr = [1,2,3,4,5];
    var content = document.getElementById('content');
    var kaiShi = document.getElementById('kaiShi');
    var zanTing = document.getElementById('zanTing');
    var timer;//计时器
    var testNum = true;

    zanTing.onclick = function () {
        if (testNum) {

            start();
            zanTing.innerHTML = '暂停';
            testNum = false;
        } else {

            stop();
            zanTing.innerHTML = '开始';
            testNum = true;
        }
    }

    function start() {
        timer = setInterval(function () {
            var num = random(0, arr.length - 1);
            kaiShi.innerHTML = arr[num];
        }, 50)
    }

    function stop() {
        clearInterval(timer);
    }

    // 随机函数
    function random(a, b) {
        var randomNum = Math.round(Math.random() * (b - a) + a);
        return randomNum;
    }
</script>
</body>
</html>